import {ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea} from '@ant-design/pro-components';
import {Form} from 'antd';
import {useModel} from "@@/exports";
import {listLicenseTypeAPI} from "@/pages/license-type/services";

export type FormValueType = {
  userId?: number;
  enrollmentType?: string;
  learningStatus?: number;
  theoryScore?: number;
  drivingScore?: number;
  paidStatus?: string;
  remark?: string;
} & Partial<API.IStudent>;

export type CreateFormProps = {
  visible: boolean;
  onVisibleChange: (visible: boolean) => void;
  onFinish: (values: API.IStudent) => Promise<void>;
};

const CreateForm: React.FC<CreateFormProps> = (props) => {
  const [form] = Form.useForm();
  const {loadDictData} = useModel('dict');

  return (
    <ModalForm
      title="新增学员"
      width="600px"
      form={form}
      visible={props.visible}
      onVisibleChange={props.onVisibleChange}
      onFinish={props.onFinish}
      modalProps={{
        destroyOnClose: true,
      }}
      grid
      rowProps={{
        gutter: 16,
      }}
    >

      <ProFormSelect
        name="enrollmentType"
        label="报名类型"
        request={async () => {
          const {data} = await listLicenseTypeAPI({});
          return (data || []).map((item: API.ILicenseType) => {
            return {
              label: item.licenseCode,
              value: item.licenseCode,
            }
          })
        }}
        placeholder="请选择报名类型"
        rules={[{required: true, message: '请选择报名类型'}]}
        colProps={{span: 12}}
      />
      <ProFormText
        name="name"
        label="姓名"
        colProps={{span: 12}}
        rules={[{required: true, message: '请输入姓名'}]}
      />
      <ProFormText
        name="idCard"
        label="身份证号"
        colProps={{span: 12}}
        rules={[{required: true, message: '请输入身份证号'}]}
      />
      <ProFormText
        name="phone"
        label="手机号"
        colProps={{span: 12}}
        rules={[{required: true, message: '请输入手机号'}]}
      />
      <ProFormSelect
        name="learningStatus"
        label="学籍状态"
        colProps={{span: 12}}
        valueEnum={{
          1: '在籍',
          2: '休学',
          3: '退学',
          4: '毕业',
        }}
        placeholder="请选择学籍状态"
        rules={[{required: true, message: '请选择学籍状态'}]}
      />
      <ProFormText
        name="theoryScore"
        label="理论成绩"
        colProps={{span: 12}}
      />

      <ProFormText
        name="drivingScore"
        label="路考成绩"
        colProps={{span: 12}}
      />
      <ProFormTextArea
        name="remark"
        label="备注"
        width="xl"
      />
    </ModalForm>
  );
};

export default CreateForm;
